<!-- 
  @name: 加注记录
  @date: 2020.1.9
 -->
<template>
	<view class="content">
		<view class="fixed_top">
			<!-- 筛选 -->
			<view class="select">
				<view class="all" @tap="allSelect">全部</view>
				<!-- 车牌号筛选区域 -->
				<view class="lic-view" @tap="licOpenClose">
					<view class="text">筛选</view>
					<view class="icon ">
						<view class="num" :class="[isActive?'active':'']">{{liceList.length}}</view>
						<view class="icon-2"></view>
					</view>
				</view>
				<view style="flex: 1;"></view>
				<!-- 日期筛选区域 -->
				<view class="date-view" @tap="dateOpenClose">
					<view class="way-1" v-show="dateType === 0">
						<text class="mon">{{month}}</text>
						<text class="date">月{{year}}年</text>
					</view>
					<view class="way-2" v-show="dateType === 1">
						<view>{{startTime}}</view>
						<view>{{endTime}}</view>
					</view>
				</view>
			</view>
			
			<!-- 统计 -->
			<view class="total">
				<view class="item">
					<text class="text">加注总量</text>
					<text class="num">{{totalNum}}kg</text>
				</view>
				<view class="item">
					<text class="text">总金额</text>
					<text class="icon">￥</text>
					<text class="num">{{totalMoney}}</text>
				</view>
			</view>
			
		</view>
		
		<!-- 日期筛选遮罩层 -->
		<date-select
			:show="showPopup"
			:start="startTime"
			:end="endTime"
			:type="dateType"
			@submit="onSubmit"
			@cancle="onCancle">
		</date-select>
		
		<!-- 车牌号筛选遮罩层 -->
		<view class="_popup lic" v-show="isLicSel" @tap="licOpenClose"></view>
		<view class="license" v-show="isLicSel">
			<view class="title">车牌号</view>
			<view class="lic-list" v-if="carList.length > 0">
				<view
					class="btn"
					v-for="(item, index) in carList"
					:key="item.carId"
					:class="liceListTmp.indexOf(item.carNumber) >= 0 ? 'b2' : 'b1'"
					@tap="licSelect(item, index)">
					{{item.carNumber}}
				</view>
			</view>
			<view class="nodata" v-if="carList.length === 0">暂无车辆</view>
			<view class="handle">
				<view class="btn" @tap="licReset">重置</view>
				<view class="btn.b2" @tap="licSubmit">
					<text>完成</text>
					<text class="num">{{liceListTmp.length}}</text>
				</view>
			</view>
		</view>
		
		<!-- 列表 -->
		<view class="record-list">
			<view
				class="item"
				v-for="(item, index) in lists"
				:key="item.recordId"
				@tap="$navigateTo('./details?recordId=' + item.recordId)">
				<view class="time">{{item.fillDayTime}} {{item.fillTime}}</view>
				<view class="icon-1"></view>
				<view class="num">{{item.actualNum}}kg</view> 
				<view class="icon-2"></view>
				<view class="mey">{{item.moneyPay}}元</view>
			</view>
			<!-- 底部加载提示 -->
			<btm-load v-if="lists.length!=0"></btm-load>
		</view>
		<view class="no-data" v-if="!lists.length">
			<image src="../static/wxImage/bg-noData.png" mode="aspectFill"></image>
			<view>暂无数据</view>
		</view>
		<!-- 登录提示 -->
		<sign-in @submit="reLogin"></sign-in>
		
	</view>
</template> 

<script>
	export default {
		data() {
			return {
				lists: [],  //加注记录
				totalNum: '0',  //加注总量
				totalMoney: '0',  //加注总额
				page: 1,
				//日期筛选
				showPopup: false,  //显示日期筛选
				dateType: 0,  //方式，0-按月筛选，1-按日筛选
				year: 2020,  //按月筛选-年份
				month: 1,  //按月筛选-月份
				startTime: '2000-1-1',  //开始日期-提交
				endTime: '2020-1-1',  //结束日期-提交
				//牌照筛选
				isLicSel: false,  //是否筛选车牌号
				carList: [],  //车辆列表
				carNumber: '',  //最终确定的车牌号（处理后）
				liceList: [],  //最终确定的选择的车牌号集合
				liceListTmp: [],  //筛选时点击的车牌号集合
			}
		},
		computed: {
			isActive() {
				return this.liceList.length != 0;
			}
		},
		onLoad() {
			this.getDate();
			this.getList();
			this.getCar();
		},
		onReachBottom() {
			this.$store.commit('btmLoad', true);
			this.getList();
		},
		onPullDownRefresh() {
			this.reLogin();
		},
		methods: {
			
			//重新登录
			reLogin() {
				this.showPopup = false;
				this.hasSelect();
			},
			//已经筛选过
			hasSelect() {
				this.page = 1;
				this.lists = [];
				this.getList();
			},
			//获取日期
			getDate() {
				this.endTime = this.$getToday();
				let arr = this.endTime.split('-');
				this.startTime = arr[0] + '-' + arr[1] + '-1';
				this.year = arr[0];
				this.month = arr[1];
			},
			//获取记录
			getList() {
				this.$http({
					url: this.$api.recordUrl + 'getrecordpage',
					data: {
						carNumber: this.carNumber,
						startTime: this.startTime,
						endTime: this.endTime,
						page: this.page,
						rows: this.$tmp.ROWS_RET
					},
					loading: this.page > 1 ? 0 : ''
				}).then(res => {
					this.totalNum = res.totalNum;
					this.totalMoney = res.totalMoney;
					let arr = res.lstFillRecord;
					if(arr && arr.length > 0) {
						this.lists = this.lists.concat(arr);
						this.page += 1;
					}
				});
			},
			//获取全部记录
			allSelect() {
				this.showPopup = false;
				this.isLicSel = false;
				this.carNumber = '';
				this.liceList = [];
				this.dateType = 0;
				this.getDate();
				this.hasSelect();
			},
			//打开/关闭日期筛选弹窗
			dateOpenClose() {
				this.isLicSel = false;
				this.showPopup = !this.showPopup;
			},
			//确认日期筛选
			onSubmit(start, end, type) {
				this.showPopup = false;
				this.dateType = type;
				this.startTime = start;
				this.endTime = end;
				if(type === 0) {
					let arr = this.startTime.split('-');
					this.year = arr[0];
					this.month = parseInt(arr[1]);
				}
				this.hasSelect();
			},
			//取消日期筛选
			onCancle(bool) {
				this.showPopup = bool;
			},
			//打开/关闭车牌号筛选区域
			licOpenClose() {
				this.showPopup = false;
				this.isLicSel = !this.isLicSel;
				//因为是打开/关闭区域，所以显示的时候已最终确认的为准
				this.liceListTmp = JSON.parse(JSON.stringify(this.liceList));
			},
			//点击完成键
			licSubmit() {
				this.isLicSel = false;
				this.liceList = JSON.parse(JSON.stringify(this.liceListTmp));
				if(this.liceList.length > 0) {
					this.carNumber = this.$arrToStr(this.liceList);
				} else {
					this.carNumber = '';
				}
				this.hasSelect();
			},
			//重置筛选条件
			licReset() {
				this.liceListTmp = [];
			},
			//点击车牌号
			licSelect(item, index) {
				let m = this.liceListTmp.indexOf(item.carNumber);
				if (m >= 0) {
					this.liceListTmp.splice(m, 1);
				}else {
					this.liceListTmp.push(item.carNumber);
				}
			},
			//获取车牌号
			getCar() {
				this.$http({
					url: this.$api.userUrl + 'getmycarlist',
					data: {
						isNavigate: 0
					}
				}).then(res => {
					this.carList = [];
					this.carList = this.carList.concat(res);
				});
			}
		}
	}
</script>

<style lang="scss">

	.no-data {
		text-align: center;
		padding-top: 300rpx;
		image {
			width: 100vw;
		}
		view {
			color: #888;
		}
	}
	
	.fixed_top {
		height: 240rpx;
	}
	
	/* 筛选 */
	.select {
		width: 750rpx;
		height: 110rpx;
		padding: 0 30rpx;
		padding-bottom: 14rpx;
		display: flex;
		flex-direction: row;
		align-items: flex-end;
		background-color: $color-white;
		.lic-view {
			margin-left: 96rpx;
			display: flex;
			flex-direction: row;
			align-items: flex-end;
			.icon {
				margin-left: 6rpx;
				.num {
					height: 28rpx;
					line-height: 27rpx;
					padding: 0 8rpx;
					font-size: 24rpx;
					color: $color-white;
					font-family: $font-family-num;
					background-color: $color-text;
					border-radius: $border-radius-bm;
					&.active {
						background-color: #0DC887;
					}
				}
				.icon-2 {
					width: 23rpx;
					height: 23rpx;
					margin-top: 10rpx;
					margin-bottom: 7rpx;
					background-image: url('http://img.etubang.com/group1/M00/00/40/rBCky14XzgWAVRMAAAADGlVHMWM008.png');
				}
				
			}
		}
		.date-view {
			text-align: end;
			.way-1 {
				font-family: $font-family-num;
				.mon {
					font-size: 50rpx;
				}
				.date {
					margin-left: 2rpx;
					font-size: 24rpx;
				}
			}
			.way-2 {
				font-family: $font-family-num;
				
				view {
					font-size: 30rpx;
				}
			}
		}
	}
	
	/* 统计 */
	.total {
		width: 750rpx;
		height: 110rpx;
		padding: 15rpx 30rpx;
		padding-bottom: 0;
		background-color: $color-white;
		display: flex;
		flex-direction: row;
		.item {
			flex: 1;
			.text {
				font-size: 20rpx;
				color: $color-grey-dark;
			}
			.num {
				margin-left: 14rpx;
				font-size: 50rpx;
				font-family: $font-family-num;
			}
			.icon {
				font-size: 36rpx;
				margin-left: 14rpx;
			}
		}
	}
	
	/* 列表 */
	.record-list {
		width: 750rpx;
		height: auto;
		margin-top: 230rpx;
		.item {
			width: 100%;
			margin-top: $spacing-col;
			padding: 40rpx 30rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			background-color: $color-white;
			.time {
				width: 330rpx;
			}
			.icon-1 {
				width: 24rpx;
				height: 32rpx;
				background-image: url('/pagesUc/static/wxImage/icon-shuidi.png');
			}
			.num {
				width: 160rpx;
				margin-left: 18rpx;
			}
			.icon-2 {
				width: 32rpx;
				height: 32rpx;
				background-image: url('/pagesUc/static/wxImage/icon-money2.png');
			}
			.mey {
				flex: 1;
				margin-left: 20rpx;
			}
		}
	}
	
	/* 筛选 */
	._popup.lic,
	.license {
		top: 110rpx;
	}
	/* 车牌号筛选遮罩层 */
	.license {
		position: fixed;
		z-index: $z-index-popup-info;
		width: 750rpx;
		background-color: $color-white;
		overflow: hidden;
		.title {
			margin-left: 30rpx;
			padding-top: 50rpx;
		}
		.lic-list {
			width: 100%;
			height: auto;
			max-height: 450rpx;
			padding: 20rpx 2rpx;
			padding-top: 0;
			margin-top: 20rpx;
			overflow-y: scroll;
			-webkit-overflow-scrolling: touch;
			
			.btn {
				display: inline-block;
				padding: 32rpx 35rpx;
				margin: 20rpx 26rpx;
				border-radius: $border-radius-bm;
			}
			.btn.b1 {
				background-color: $color-bg;
			}
			.btn.b2 {
				color: $color-primary;
				background-color: $color-bg-primary;
			}
		}
		.nodata {
			width: 100%;
			padding: 30rpx;
			color: $color-grey-dark;
		}
		.handle {
			display: flex;
			flex-direction: row;
			border-top: 1rpx solid $color-list;
			.btn {
				flex: 1;
				height: 122rpx;
				line-height: 122rpx;
				text-align: center;
				font-size: 30rpx;
			}
			.btn.b2 {
				background-color: $color-primary;
				.num {
					height: 30rpx;
					line-height: 29rpx;
					margin-left: 9rpx;
					padding: 1rpx 10rpx;
					font-size: 24rpx;
					color: $color-white;
					font-family: $font-family-num;
					background-color: $color-text;
					border-radius: $border-radius-bm;
				}
			}
		}
	}
</style>
